<?php include("../config.php"); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title><?php echo $sitename; ?> - Sysop: PAD List Submission</title>
<meta name="description" content="<?php echo $sitename; ?> - Sysop: PAD List Submission">
<meta name="keywords" content="free to try, software, shareware, freeware, developers, vendors, download, PAD">
<meta name="author" content="Andrey Aleksanyants, M.D.">
<meta name="copyright" content="easy HTools">
<meta http-equiv="imagetoolbar" content="no">
<link rel="stylesheet" type="text/css" href="../<?php echo $cssfile; ?>">
<link rel="shortcut icon" href="../favicon.ico">
</head>
<body>
<table class="tmain" align="center" width="90%" cellspacing="0" cellpadding="0">
<tr>
<td class="tmain">
<table class="tlogo" align="center" width="100%" cellspacing="0" cellpadding="4">
<tr>
<td align="right">
<p><a href="index.php">Home</a></p>
</td>
</tr>
</table>
</td>
</tr><tr>
<td class="tmain">
<br>
<table align="center" width="100%" border="0" cellspacing="0" cellpadding="1">
<tr valign="top">
<td class="tbody">
<h1><?php echo $sitename; ?> - Sysop: PAD List Submission</h1>

<?php

// Connecting to database
if(!($link_id = @mysql_connect($dbhost, $userid, $userpassword))) {
	die("<p><b>Error connecting to the database server:</b> " . mysql_error() . "</p>\n");
}
mysql_select_db($dbname);

$numrows = 0;
$result = mysql_query("SELECT * FROM paddata", $link_id);
if($result) $numrows = mysql_num_rows($result);
echo "<p>There are <b>" . $numrows . "</b> PADs listed in your database.</p><br>\n";

// Requesting data from Add PAD List form on /sysop/index.php
$padlist  = $_POST["padlist"];
$row      = $_POST["row"];
$apbutton = $_POST["apbutton"];

if(empty($apbutton)) {
	echo "<form action=\"" . $PHP_SELF . "\" method=\"post\">\n";
	echo "<table class=\"tvisible\" align=\"center\" cellspacing=\"0\" cellpadding=\"4\">\n";
	echo "<tr>\n";
	echo "<th class=\"tablehead\" colspan=\"2\">PAD List Submission</th>\n";
	echo "</tr><tr>\n";
	echo "<td class=\"tdark\"><label for=\"padlist\"><p><b>PAD List URL:</b></p></label></td>\n";
	echo "<td><input type=\"text\" name=\"padlist\" value=\"padlist.txt\" size=\"56\" maxlength=\"70\"></td>\n";
	echo "</tr><tr>\n";
	echo "<td class=\"tdark\"><label for=\"row\"><p><b>Begin from row:</b></p></label></td>\n";
	echo "<td><input type=\"text\" name=\"row\" value=\"1\" size=\"8\" maxlength=\"6\"></td>\n";
	echo "</tr><tr>\n";
	echo "<td class=\"tdark\"><p><b>Start:</b></p></td>\n";
	echo "<td><input type=\"submit\" class=\"button\" name=\"apbutton\" value=\"   Start   \"></td>\n";
	echo "</tr>\n</table>\n</form>\n<br>\n";
}
else { // Processing received data
	$bad = "";
	if(empty($padlist) or (strtolower($padlist) == "http://")) {
		$bad.= "<b>Error:</b> No PAD List submitted.<br>\n";
	}
	if(!intval($row)) {
		$bad.= "<b>Error:</b> Incorrect row number.<br>\n";
	}
	if($bad)
		echo "<p>" . $bad . "</p>\n<p>Go <a href=\"javascript:history.back()\">Back</a> and fill the form correctly.</p><br>\n";
	else { // Form is OK
		$reqtags = array("<XML_DIZ_INFO><COMPANY_INFO><COMPANY_NAME>",
		                 "<XML_DIZ_INFO><COMPANY_INFO><COUNTRY>",
		                 "<XML_DIZ_INFO><COMPANY_INFO><COMPANY_WEBSITE_URL>",
		                 "<XML_DIZ_INFO><COMPANY_INFO><CONTACT_INFO><CONTACT_FIRST_NAME>",
		                 "<XML_DIZ_INFO><COMPANY_INFO><CONTACT_INFO><CONTACT_LAST_NAME>",
		                 "<XML_DIZ_INFO><COMPANY_INFO><CONTACT_INFO><CONTACT_EMAIL>",
		                 "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_NAME>",
		                 "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_VERSION>",
		                 "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_RELEASE_MONTH>",
		                 "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_RELEASE_DAY>",
		                 "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_RELEASE_YEAR>",
		                 "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_COST_DOLLARS>",
		                 "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_TYPE>",
		                 "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_INSTALL_SUPPORT>",
		                 "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_OS_SUPPORT>",
		                 "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_LANGUAGE>",
		                 "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_CHANGE_INFO>",
		                 "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_CATEGORY_CLASS>",
		                 "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_SYSTEM_REQUIREMENTS>",
		                 "<XML_DIZ_INFO><PROGRAM_INFO><FILE_INFO><FILE_SIZE_K>",
		                 "<XML_DIZ_INFO><PROGRAM_DESCRIPTIONS><ENGLISH><KEYWORDS>",
		                 "<XML_DIZ_INFO><PROGRAM_DESCRIPTIONS><ENGLISH><CHAR_DESC_80>",
		                 "<XML_DIZ_INFO><PROGRAM_DESCRIPTIONS><ENGLISH><CHAR_DESC_2000>",
		                 "<XML_DIZ_INFO><WEB_INFO><APPLICATION_URLS><APPLICATION_INFO_URL>",
		                 "<XML_DIZ_INFO><WEB_INFO><APPLICATION_URLS><APPLICATION_SCREENSHOT_URL>",
		                 "<XML_DIZ_INFO><WEB_INFO><APPLICATION_URLS><APPLICATION_ICON_URL>",
		                 "<XML_DIZ_INFO><WEB_INFO><APPLICATION_URLS><APPLICATION_XML_FILE_URL>",
		                 "<XML_DIZ_INFO><WEB_INFO><DOWNLOAD_URLS><PRIMARY_DOWNLOAD_URL>",
		                 "<XML_DIZ_INFO><AFFILIATES><AFFILIATES_ESELLERATE_PRODUCT_ID>",
		                 "<XML_DIZ_INFO><AFFILIATES><AFFILIATES_PLIMUS_PRODUCT_ID>",
		                 "<XML_DIZ_INFO><AFFILIATES><AFFILIATES_REGNOW_PRODUCT_ID>",
		                 "<XML_DIZ_INFO><AFFILIATES><AFFILIATES_SHAREIT_PRODUCT_ID>",
		                 "<XML_DIZ_INFO><ASP><ASP_MEMBER_NUMBER>");
		
		function GetStartTag($parser,$element_name,$element_attribs) {
			global $tagstack;
			$tagstack .= "<" . $element_name . ">";
		}
		
		function GetData($parser,$data) {
			global $tagstack, $tagarray, $lasttag;
			if($lasttag == $tagstack) {
				$tagarray["$tagstack"] .= $data;
			}
			else {
				$tagarray["$tagstack"]  = $data;
			}
			$lasttag = $tagstack;
		}
		
		function GetEndTag($parser,$element_name) {
			global $tagstack;
			$x = "<" . $element_name . ">";
			if(strrchr($tagstack,$x) == $x) {
				$tagstack = substr($tagstack,0,strrpos($tagstack,$x));
			}
			else {
				echo "<p><b>Error:</b> no corresponding start tag for end tag: " . htmlspecialchars($x) . "</p><br>\n";
				continue;
			}
		}
		
		$starttime = time();
		ini_set("max_execution_time","3600");  // 1-hour script timeout
		
		$count    = 0;
		$accepted = 0;
		//echo $padlist;
		// Processing text file with URL list begin
		if(!file_exists($padlist)) die("<p><b>Error opening PAD List URL from \"" . $padlist . "\".</b><br>Go <a href=\"javascript:history.back()\">Back</a> and check URL.</p><br>\n");
		$padary = file($padlist);
		$row-=1;
		for($i=$row; $i<count($padary); $i++) {
			$padurl = rtrim($padary[$i]);
			$count++;
			echo "<p><b>" . $count . ". PAD URL: " . $padurl . "</b></p>\n";
			
			flush(); // Flush the output PHP buffer
			unset($tagarray);
			$tagstack = "";
			$lasttag = "?";
			
			$paderr = "";
			//echo $padurl;
			$padurl=trim($padurl);
			// Reading XML PAD file
			//if(!($data = @file($padurl))) {
			if(!@file("$padurl")) {
				echo "<p><b>Error opening PAD URL!</b></p>\n<hr>\n";
				continue;
			}
			$data = @file("$padurl");
			//print_r($data);
			$data = implode("",$data);
			//print_r($data);
			if(strpos($data, "<XML_DIZ_INFO>") === FALSE) {
				echo "<p><b>File format error: this file does not contain XML PAD data!</b></p>\n<hr>\n";
				continue;
			}
			
			// Look up the XML encoding
			if(preg_match("/<\?xml [^>]*encoding=['\"](.*?)['\"][^>]*>.*/", $data, $encarray)) {
				$encoding = strtoupper($encarray[1]);
			}
			else {
				$encoding = "UTF-8";
			}
			// If the encoding is not natively supported by the PHP XML parser, try to
			// decode on our own (to UTF-8), if decoding is not possible, assume UTF-8,
			// which is the XML default.
			if(($encoding != "UTF-8") &&($encoding != "US-ASCII") &&($encoding != "ISO-8859-1")) {
				$encoding = "";
				if(function_exists("mb_convert_encoding")) {
					$encoded_source = @mb_convert_encoding($data, "UTF-8", $encoding);
					if( $encoded_source != NULL ) {
						$data = str_replace($encarray[0], "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>", $encoded_source);
						$encoding = "UTF-8";
					}
				}
			}
			
			// Create an XML parser
			if(!($xml_parser = xml_parser_create($encoding))) {
				echo "<p><b>Error creating XML parser!</b></p>\n<hr>\n";
				break;
			}
			// Set ISO-8859-1 as target encoding for XML parser
			xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, "ISO-8859-1");
			
			// Set the functions to handle opening and closing tags
			xml_set_element_handler($xml_parser,"GetStartTag","GetEndTag");
			
			// Set the function to handle blocks of character data
			xml_set_character_data_handler($xml_parser,"GetData");
			
			if(!xml_parse($xml_parser,$data,true)) { // Handle errors in parsing
				$paderr .= sprintf("<p><b>XML parsing error:</b> %s at line %d, column %d</p>\n<hr>\n", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser), xml_get_current_column_number($xml_parser));
			}
			
			// Free up memory used by the XML parser
			xml_parser_free($xml_parser);
			
			if($paderr) {
				echo $paderr;
				continue;
			}
			
			// Setting defaults if blank
			$tag = "<XML_DIZ_INFO><COMPANY_INFO><COUNTRY>";
			if(empty($tagarray["$tag"]) or trim($tagarray["$tag"] == "")) $tagarray["$tag"] = "none";
			
			$tag = "<XML_DIZ_INFO><COMPANY_INFO><CONTACT_INFO><CONTACT_FIRST_NAME>";
			if(empty($tagarray["$tag"]) or trim($tagarray["$tag"] == "")) $tagarray["$tag"] = "Anonym";
			
			$tag = "<XML_DIZ_INFO><COMPANY_INFO><CONTACT_INFO><CONTACT_LAST_NAME>";
			if(empty($tagarray["$tag"]) or trim($tagarray["$tag"] == "")) $tagarray["$tag"] = "Author";
			
			$tag = "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_COST_DOLLARS>";
			if(empty($tagarray["$tag"]) or trim($tagarray["$tag"] == "")) $tagarray["$tag"] = "0.00";
			
			$tag = "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_CHANGE_INFO>";
			if(empty($tagarray["$tag"]) or trim($tagarray["$tag"] == "")) $tagarray["$tag"] = "Not Established";
			
			$tag = "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_SYSTEM_REQUIREMENTS>";
			if(empty($tagarray["$tag"]) or trim($tagarray["$tag"] == "")) $tagarray["$tag"] = "Not Established";
			
			$tag = "<XML_DIZ_INFO><PROGRAM_INFO><PROGRAM_LANGUAGE>";
			if(empty($tagarray["$tag"]) or trim($tagarray["$tag"] == "")) $tagarray["$tag"] = "Not Established";
			
			$tag = "<XML_DIZ_INFO><PROGRAM_DESCRIPTIONS><ENGLISH><KEYWORDS>";
			if(empty($tagarray["$tag"]) or trim($tagarray["$tag"] == "")) $tagarray["$tag"] = "free, program, download";
			
			$tag = "<XML_DIZ_INFO><WEB_INFO><APPLICATION_URLS><APPLICATION_SCREENSHOT_URL>";
			if(empty($tagarray["$tag"]) or trim($tagarray["$tag"] == "")) $tagarray["$tag"] = "none";
			
			$tag = "<XML_DIZ_INFO><WEB_INFO><APPLICATION_URLS><APPLICATION_ICON_URL>";
			if(empty($tagarray["$tag"]) or trim($tagarray["$tag"] == "")) $tagarray["$tag"] = "none";
			
			$tag = "<XML_DIZ_INFO><AFFILIATES><AFFILIATES_ESELLERATE_PRODUCT_ID>";
			if(empty($tagarray["$tag"]) or trim($tagarray["$tag"] == "")) $tagarray["$tag"] = "none";

			$tag = "<XML_DIZ_INFO><AFFILIATES><AFFILIATES_PLIMUS_PRODUCT_ID>";
			if(empty($tagarray["$tag"]) or trim($tagarray["$tag"] == "")) $tagarray["$tag"] = "none";

			$tag = "<XML_DIZ_INFO><AFFILIATES><AFFILIATES_REGNOW_PRODUCT_ID>";
			if(empty($tagarray["$tag"]) or trim($tagarray["$tag"] == "")) $tagarray["$tag"] = "none";

			$tag = "<XML_DIZ_INFO><AFFILIATES><AFFILIATES_SHAREIT_PRODUCT_ID>";
			if(empty($tagarray["$tag"]) or trim($tagarray["$tag"] == "")) $tagarray["$tag"] = "none";

			$tag = "<XML_DIZ_INFO><ASP><ASP_MEMBER_NUMBER>";
			if(empty($tagarray["$tag"]) or trim($tagarray["$tag"] == "")) $tagarray["$tag"] = "none";
			
			// Checking for missing/empty tags
			foreach($reqtags as $tag) {
				if(empty($tagarray["$tag"])) {
					$paderr .= "<p><b>Required tag not found in PAD file:</b><br>\n" . htmlspecialchars($tag) . "</p>\n";
					continue;
				}
			}
			if($paderr) {
				echo $paderr;
				echo "<p><b>PAD file rejected!</b></p>\n<hr>\n";
				continue;
			}
			
			$tag = $reqtags[0];  $company         = substr($tagarray["$tag"], 0, 50); 
			$tag = $reqtags[1];  $country         = substr($tagarray["$tag"], 0, 50);
			$tag = $reqtags[2];  $website         = substr($tagarray["$tag"], 0, 128);
			$tag = $reqtags[3];  $firstname       = substr($tagarray["$tag"], 0, 64);
			$tag = $reqtags[4];  $lastname        = substr($tagarray["$tag"], 0, 64);
			$tag = $reqtags[5];  $email           = substr($tagarray["$tag"], 0, 50);
			$tag = $reqtags[6];  $title           = substr($tagarray["$tag"], 0, 50);
			$tag = $reqtags[7];  $version         = substr($tagarray["$tag"], 0, 15);
			$tag = $reqtags[8];  $pmonth          = $tagarray["$tag"];
			$tag = $reqtags[9];  $pday            = $tagarray["$tag"];
			$tag = $reqtags[10]; $pyear           = $tagarray["$tag"];
			$tag = $reqtags[11]; $cost            = $tagarray["$tag"];
			$tag = $reqtags[12]; $ptype           = substr($tagarray["$tag"], 0, 15);
			$tag = $reqtags[13]; $install         = substr($tagarray["$tag"], 0, 50);
			$tag = $reqtags[14]; $os              = substr($tagarray["$tag"], 0, 80);
			$tag = $reqtags[15]; $languages       = substr($tagarray["$tag"], 0, 255);
			$tag = $reqtags[16]; $changeinfo      = $tagarray["$tag"];
			$tag = $reqtags[17]; $category        = substr($tagarray["$tag"], 0, 80);
			$tag = $reqtags[18]; $requirements    = substr($tagarray["$tag"], 0, 200);
			$tag = $reqtags[19]; $ksize           = $tagarray["$tag"];
			$tag = $reqtags[20]; $keywords        = substr($tagarray["$tag"], 0, 128);
			$tag = $reqtags[21]; $description     = substr($tagarray["$tag"], 0, 80);
			$tag = $reqtags[22]; $descrlarge      = substr($tagarray["$tag"], 0, 2000);
			$tag = $reqtags[23]; $homepage        = substr($tagarray["$tag"], 0, 128);
			$tag = $reqtags[24]; $screenshot      = substr($tagarray["$tag"], 0, 128);
			$tag = $reqtags[25]; $icon            = substr($tagarray["$tag"], 0, 128);
			$tag = $reqtags[26]; $padfile         = substr($tagarray["$tag"], 0, 128);
			$tag = $reqtags[27]; $download        = substr($tagarray["$tag"], 0, 128);
			$tag = $reqtags[28]; $esellerateid    = substr($tagarray["$tag"], 0, 16);
			$tag = $reqtags[29]; $plimusid        = substr($tagarray["$tag"], 0, 16);
			$tag = $reqtags[30]; $regnowid        = substr($tagarray["$tag"], 0, 16);
			$tag = $reqtags[31]; $shareitid       = substr($tagarray["$tag"], 0, 16);
			$tag = $reqtags[32]; $aspnumber       = substr($tagarray["$tag"], 0, 5);
			$my_affilate = $tagarray["<XML_DIZ_INFO><WEB_INFO><APPLICATION_URLS><APPLICATION_ORDER_URL>"];
			
			if(strstr($my_affilate,"regnow")){
				$i_affilate = "RegNow";
				$i_affilateid = strstr($my_affilate,"item=");
				$i_affilateid = substr($i_affilateid,5);
				
			}
			if(strstr($my_affilate,"shareit")){
				$i_affilate = "Share-It";
				$i_affilateid = strstr($my_affilate,"productid=");
				$i_affilateid = substr($i_affilateid,10);
			}
			if(strstr($my_affilate,"esellerate")){
				$i_affilate = "eSellerate";
				$i_affilateid = strstr($my_affilate,"c=0_");
				$i_affilateid = substr($i_affilateid,4);
			}
			if(strstr($my_affilate,"plimus")){
				$i_affilate = "Plimus";
				$i_affilateid = strstr($my_affilate,"contractId=");
				$i_affilateid = substr($i_affilateid,11);
			}
			//exit();
			// Adding "http://" to links if missing
			if((trim($website) != "") && (strstr($website, "://") === FALSE))
				$website = "http://" . $website;
			if((trim($homepage) != "") && (strstr($homepage, "://") === FALSE))
				$homepage = "http://" . $homepage;
			if((trim($download) != "") && (strstr($download, "://") === FALSE))
				$download = "http://" . $download;
			
			$contactname = $firstname . " " . $lastname;
			if(strlen($pmonth) == 1) $pmonth = "0" . $pmonth;
			if(strlen($pday) == 1) $pday = "0" . $pday;
			$pdate = $pyear . "-" . $pmonth . "-" . $pday;
			$ksize = str_replace(",","",$ksize);  // remove any commas
			
			// Checking release date
			$tomorrow = date("Y-m-d",time()+86400);
			if($pdate > $tomorrow) {
				echo "<p><b>Error:</b> Program release date (" . $pdate . ") is greater than tomorrow's date (" . $tomorrow . ")!</p>\n<hr>\n";
				continue;
			}
			
			// Checking PAD URL inside PAD file
			if($padfile != $padurl) {
				echo "<p><b>Error:</b> Submitted URL (" . $padurl . ") does not match URL inside PAD file (" . $padfile . ")!</p>\n<hr>\n";
				continue;
			}
			
			// Checking Category
			$catfile = "../categories.txt";
			$catary = file($catfile);
			$isvalidcat = false;
			for($ii=0; $ii<count($catary); $ii++) {
				$cdisp = rtrim($catary[$ii]);
					if(($category == $cdisp) || ($category == htmlspecialchars($cdisp))) {
					$isvalidcat = true;
					break;
				}
			}
			if(!$isvalidcat) {
				echo "<p><b>Error:</b> Unrecognized category " . $category . "!</p>\n<hr>\n";
				continue;
			}
			
			// Checking screenshot and icon URLs
			if(($screenshot != "none") && (strstr($screenshot, "://") or (strstr($screenshot, ".gif") && strstr($screenshot, ".jpg") && strstr($screenshot, ".png"))) === FALSE) {
				$screenshot = "none";
			}
			if(($icon != "none") && (strstr($icon, "://") or (strstr($icon, ".gif") && strstr($icon, ".jpg") && strstr($icon, ".png"))) === FALSE) {
				$icon = "none";
			}

			// Processing affiliate data from PAD if available
			if($esellerateid != "none") {
				$affiliate   = "eSellerate";
				$affiliateid = $esellerateid;
			}
			if($plimusid != "none") {
				$affiliate   = "Plimus";
				$affiliateid = $plimusid;
			}
			if($regnowid != "none") {
				$affiliate   = "RegNow";
				$affiliateid = $regnowid;
			}
			if($shareitid != "none") {
				$affiliate   = "Share-It";
				$affiliateid = $shareitid;
			}
			else {
				$affiliate   = "";
				$affiliateid = "";
			}
			
			$company       = addslashes($company);
			$country       = addslashes($country);
			$contactname   = addslashes($contactname);
			$title         = addslashes($title);
			$version       = addslashes($version);
			$changeinfo    = addslashes($changeinfo);
			$requirements  = addslashes($requirements);
			$keywords      = addslashes($keywords);
			$description   = addslashes($description);
			$descrlarge    = addslashes($descrlarge);
			$poll          = 0;
			
			// Checking if company/title or PAD URL already in paddata table
			$result = mysql_query("SELECT * FROM paddata WHERE padfile = '$padfile'", $link_id);
			$query = mysql_fetch_array($result);
			if(empty($query)) { // If there was no such entry in database
				// Adding new software to paddata table
				if(!mysql_query("INSERT INTO paddata (company, country, website, contactname, email, title, version, pdate, cost, ptype, install, os, languages, changeinfo, category, requirements, ksize, keywords, description, descrlarge, homepage, screenshot, icon, padfile, download, aspnumber, poll,affiliate,affiliateid) VALUES ('$company', '$country', '$website', '$contactname', '$email', '$title', '$version', '$pdate', '$cost', '$ptype', '$install', '$os', '$languages', '$changeinfo', '$category', '$requirements', '$ksize', '$keywords', '$description', '$descrlarge', '$homepage', '$screenshot', '$icon', '$padfile', '$download', '$aspnumber', '$poll','$i_affilate','$i_affilateid')", $link_id)) {
					echo "<p><b>Error inserting new data in paddata table:</b> " . mysql_error() . "</p>\n<hr>\n";
					continue;
				}
				$progid = sprintf("%d", mysql_insert_id($link_id));
				echo "<p>New program successfully added. View details <a href=\"/details.php?progid=" . $progid . "\">here</a>.</p>\n<hr>\n";
			}
			else {
				$progid      = $query["progid"];
				// Updating the existing software in paddata table
				if(!mysql_query("UPDATE paddata SET company = '$company', country = '$country', website = '$website', contactname = '$contactname', email = '$email', title = '$title', version = '$version', pdate = '$pdate', cost = '$cost', ptype = '$ptype', status = '$status', install = '$install', os = '$os', languages = '$languages', changeinfo = '$changeinfo', category = '$category', requirements = '$requirements', ksize = '$ksize', keywords = '$keywords', description = '$description', descrlarge = '$descrlarge', homepage = '$homepage', screenshot = '$screenshot', icon = '$icon', padfile = '$padfile', download = '$download', aspnumber = '$aspnumber', poll = '$poll',affiliate = '$i_affilate' ,affiliateid = '$i_affilateid' WHERE progid = '$progid'", $link_id)) {
					echo "<p><b>Error updating existing data in paddata table:</b> " . mysql_error() . "</p>\n<hr>\n";
					continue;
				}
				echo "<p>Existing program record successfully updated. View details <a href=\"/details.php?progid=" . $progid . "\">here</a>.</p>\n<hr>\n";
			}
			
			$accepted++;
		}
		
		echo "<p><b>PAD files processed:</b> " . $count . "</p>\n";
		echo "<p><b>PAD files accepted:</b> " . $accepted . "</p>\n";
		echo "<p><b>PAD files rejected:</b> " . ($count-$accepted) . "</p><br>\n";
		
		$elapsed = time() - $starttime;
		$min = intval($elapsed / 60);
		$sec = $elapsed % 60;
		echo "<p><b>Elapsed time:</b> " . $min . " minutes, " . $sec . " seconds.</p><br>\n";
	}
}
// Disconnect from database
mysql_close($link_id);
?>
<br>

</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>